home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
File class library
/
sources
/
CFolder.c
< prev
next >
Wrap
Text File
|
1992-10-08
|
3KB
|
116 lines
/*
CFolder.c
Superclass: CIsleFile
Implementation of directory manipulation.
October 8, 1992 isl
*/
#include <CFolder.h>
/*=====================*/
/*===---------------===*/
void CFolder::IFolder(void)
Begin
CIsleFile::IIsleFile();
End
/*===---------------===*/
void CFolder::CreateNew(OSType creator, OSType type)
Begin
if (ExistsOnDisk())
{ // It already exists -- what is its directory ID?
CInfoPBRec specs; // The duplicate file specifications
GetMacCatInfo(&specs);
if (specs.dirInfo.ioFlAttrib & kDirTest)
folderDirID= specs.dirInfo.ioDrDirID;
else
ErrorAlert(dupFNErr, SpecifyMsg(kFolderError, kFolderFileConflict));
}
else
FailOSErr( DirCreate(volNum, dirID, name, &folderDirID) );
End
/*===---------------===*/
void CFolder::CreateWithIcon(OSType creator, OSType type, short iconID)
Begin
CCustomIcon* itsIcon; // The icon for this folder
short counter; // Just a loop counter
CreateNew(creator, type);
TRY
{
if (fSuper && dirID)
{ // Give this new folder our icon
itsIcon= Null;
itsIcon= new CCustomIcon; // Create the custom icon object
itsIcon->ICustomIcon(); // and initialize it
itsIcon->SpecifyHFS(kCustomIconFile, volNum, folderDirID);
if (!itsIcon->ExistsOnDisk()) // Make sure not to overwrite and existing file
{ // Let's set a custom icon!
CInfoPBRec specs; // The icon file's specs
itsIcon->FetchIconFamily(iconID); // Fetch from application's resource fork
itsIcon->CreateNew(kNoSignature, kNoType); // Create a custom icon file
itsIcon->PlaceIconFamily(); // Place the needed resources
itsIcon->GetMacCatInfo(&specs); // Get the custom icon's catalog information
specs.hFileInfo.ioFlFndrInfo.fdFlags |= kInvisible;
itsIcon->SetMacCatInfo(&specs); // Make the file invisible
GetMacCatInfo(&specs); // Get the folder's catalog information
specs.dirInfo.ioDrUsrWds.frFlags &= kFlagsOff; // Turn off all Finder flags
specs.dirInfo.ioDrUsrWds.frFlags |= kCustomIcon; // Turn the hasCustomIcon bit on
SetMacCatInfo(&specs); // Register a custom icon for our folder
ForgetObject(itsIcon);
}
}
else
ErrorAlert(noErr, SpecifyMsg(kFolderError, kBadSystem));
}
CATCH
{
ForgetObject(itsIcon);
}
ENDTRY;
End
/*===---------------===*/
Boolean CFolder::ExistsOnDisk(void)
Begin
CInfoPBRec specs; // File specifications
OSErr error; // A possible error condition
specs.dirInfo.ioCompletion= Null;
specs.dirInfo.ioNamePtr= name;
specs.dirInfo.ioVRefNum= volNum;
specs.dirInfo.ioFDirIndex= kDefault;
specs.dirInfo.ioDrDirID= dirID;
error= PBGetCatInfo(&specs, False);
return (error != fnfErr);
End
/*===---------------===*/
void CFolder::GetPath(Str255 path, Str255 delimiter)
Begin
inherited::GetPath(path, delimiter);
if (path[*path] != delimiter[*delimiter])
ConcatPStrings(path, delimiter);
End
/*===---------------===*/
/*=====================*/